package com.kasinf.sample.log.config;

import com.kasinf.framework.cache.utils.RedisUtils;
import com.kasinf.framework.common.util.spring.SpringUtils;
import com.kasinf.framework.log.server.service.EsLogIndexRefresh;
import com.kasinf.framework.log.server.service.EsLogService;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @Author : Kaiser
 * @Date: 2025/6/30  16:18
 */
@Component
@RequiredArgsConstructor
public class CustomIndexRefresh implements EsLogIndexRefresh {
    @Override
    public void publish(String indexName) {
        RedisUtils.publish("log-index-refresh", indexName);
    }


    @PostConstruct
    public void init() {
        RedisUtils.subscribe("log-index-refresh", String.class, index -> {
            EsLogService logService = SpringUtils.getBean(EsLogService.class);
            logService.setCurrentIndex(index);
        });
    }
}
